package the_art_of_java_concurrency_programming.concurrent.Thread;

/**
 * 守护线程 当jvm退出时daemon线程finally块不一定被执行
 *
 * @Author: 李浩然
 * @Date: 2021/4/8 12:40 下午
 */
public class Daemon {
    public static void main(String[] args) {
        Thread thread = new Thread(new DaemonRunner(), "DaemonRunner");
        thread.setDaemon(true);
        thread.start();
    }

    static class DaemonRunner implements Runnable {
        @Override
        public void run() {
            try {
                SleepUtils.second(10);
            } finally {  //finally 块没有用
                System.out.println("DaemonThread finally run.");
            }
        }
    }
}
